from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP


def Descrypt(filename):
    code = 'nooneknows'
    with open(filename, 'rb') as fobj:
        # 导入私钥
        private_key = RSA.import_key(open('zmy_rsa').read(), passphrase=code)
        # 会话密钥， 随机数，消息认证码，机密的数据
        enc_session_key, nonce, tag, ciphertext = [fobj.read(x)
                                                   for x in (private_key.size_in_bytes(),
                                                             16, 16, -1)]
        cipher_rsa = PKCS1_OAEP.new(private_key)
        session_key = cipher_rsa.decrypt(enc_session_key)
        cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
        # 解密
        data = cipher_aes.decrypt_and_verify(ciphertext, tag)

    with open(filename, 'wb') as wobj:
        wobj.write(data)


Descrypt("e://test/music.mp3")
